﻿<!DOCTYPE html>
<html>
<head>
<!--
  Copyright (c) 2015 Jean-Marc VIGLINO,
  released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
-->
  <title>ol-ext: Overview map control</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <!-- jQuery -->
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>


  <!-- Openlayers -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@latest/ol.css" />
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ol@latest/dist/ol.js"></script>
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL,Object.assign"></script>
  
  <!-- ol-ext -->
  <link rel="stylesheet" href="../../dist/ol-ext.css" />
  <script type="text/javascript" src="../../dist/ol-ext.js"></script>
  <!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
  <script src="https://unpkg.com/elm-pep"></script>

  <link rel="stylesheet" href="../style.css" />

  <style>
    .oview {
      color: #fff;
      background: #369;
      padding: 0.5em;
      display: inline-block;
      margin-right: 0.5em;
    }
  </style>
</head>
<body>
  <a href="https://github.com/Viglino/ol-ext" class="icss-github-corner"><i></i></a>

  <a href="../../index.html">
    <h1>ol-ext: Overview map control</h1>
  </a>
  <div class="info">
    The <i>ol.control.Overview</i> create an overview similar to the <i>ol.control.overview</i>.
    <br/>
    The main differences is that you can limit the zoom level on the overview and force the overview to be oriented north.
    <ul>
    <li>
    Limiting the min zoom of the overview will magnify the map.
    </li>
    <li>
    Limiting the max zoom avoid to zoom in the overview and draw the position as a point on it when extent is too small.
    </li>
    <li>
    You can use the <i>style</i> option to choose the style of the box drawn on the overview. 
    If the box is too small a point will be drawn instead (ol.style.Image of the style).
    </li>
    </ul>
    Click on the overview map to move the center of the map to that point. 
    The <i>elastic</i> option move the map with an elastic animation.
  </div>

  <!-- the map -->
  <div id="map" style="width:600px; height:400px;"></div>

  <div>
    <div class="oview">
      External overview
      <div class="overview" style="width:150px; height:150px;"></div>
    </div>
  </div>
  
  <div class="options">
    Zoom min: <input id="minzoom" type="number" value="8" style="width:4em" />
    <br />
    Zoom max: <input id="maxzoom" type="number" value="12" style="width:4em" />
    <br />
    Layer: 
    <select onchange="setOVLayer(this)">
      <option value="0">OSM</option>
      <option value="1" selected>Photo</option>
    </select>
    <br />
    <input id="rotate" type="checkbox" /><label for="rotate"> Rotate overview map</label>
    <br />
    Position:
    <select id="align" onchange="ov.setPosition(this.value)">
      <option value="bottom-left">bottom-left</option>
      <option value="bottom-right">bottom-right</option>
      <option value="top-left">top-left</option>
      <option value="top-right">top-right</option>
    </select>
  </div>

  <script type="text/javascript">
    // The map
    var map=new ol.Map ({
      target: 'map',
      view: new ol.View ({
        zoom: 15,
        center: [270148, 6247782]
      }),
      layers: [ new ol.layer.Geoportail('GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2') ]
    });

    // Layers for the overview
    var layers = [
      new ol.layer.Tile({	source: new ol.source.OSM()	}),
      new ol.layer.Geoportail('ORTHOIMAGERY.ORTHOPHOTOS')
    ];
    var layers2 = [
      new ol.layer.Tile({	source: new ol.source.OSM()	}),
      new ol.layer.Geoportail('ORTHOIMAGERY.ORTHOPHOTOS')
    ];

    // New control on the map
    var ov = new ol.control.Overview({
      layers: layers,
      minZoom: $("#minzoom").val(),
      maxZoom: $("#maxzoom").val(),
      rotation: $("#rotate").prop("checked"),
      align: $("#align").val(),
      panAnimation: "elastic"
    });
    map.addControl(ov);

    // New control outside the map (styled)
    var ov2 = new ol.control.Overview({
      target: $(".overview").get(0),
      layers: layers2,
      minZoom: $("#minzoom").val(), maxZoom: $("#maxzoom").val(),
      rotation: $("#rotate").prop("checked"),
      style: [ new ol.style.Style({
        image: new ol.style.Circle({
          fill: new ol.style.Fill({
            color: 'rgba(0,255,102, 1)'
          }),
          stroke: new ol.style.Stroke({
            width: 7,
            color: 'rgba(0,255,102, 0.8)'
          }),
          radius: 5
        }),
        stroke: new ol.style.Stroke({
          width: 3,
          color: "rgba(0,255,102,1)",
          lineDash: [5, 5]
        })
      })]
    });
    map.addControl(ov2);

    // Options changes
    function setOVLayer (e) {
      ov.getOverviewMap().getLayers().getArray()[$(e).val()].setVisible(true);
      ov.getOverviewMap().getLayers().getArray()[1-$(e).val()].setVisible(false);
      ov2.getOverviewMap().getLayers().getArray()[$(e).val()].setVisible(true);
      ov2.getOverviewMap().getLayers().getArray()[1-$(e).val()].setVisible(false);
    }
    $("#rotate").on("change", function () {
      ov.rotation = ov2.rotation=$("#rotate").prop("checked");
      ov.setView();
      ov2.setView();
    });
    $("#minzoom").on("change", function () {
      ov.minZoom = ov2.minZoom=Number($("#minzoom").val());
      ov.setView();
      ov2.setView();
    });
    $("#maxzoom").on("change", function () {
      ov.maxZoom = ov2.maxZoom=Number($("#maxzoom").val());
      ov.setView();
      ov2.setView();
    });
  </script>

</body>
</html>